package com.itheima.练习.test3;

import java.io.*;
import java.net.Socket;

//客户端
public class Client {
    public static void main(String[] args) throws IOException {
        //一传递，一读取
        Socket socket=new Socket("127.0.0.1",10000);

        BufferedInputStream bis=new BufferedInputStream(new FileInputStream("E:\\4399\\1692958019607.png"));
        //缓冲输入流bis
        BufferedOutputStream bos=new BufferedOutputStream(socket.getOutputStream());
        //输出流往服务器写出数据
        //一个字节一个写的太慢，用缓冲输出流bos

        byte[]bytes=new byte[2048];
        int b;
        while ((b=bis.read(bytes))!=-1){
            bos.write(bytes,0,b);
        }//读取bis里的文件，并用bos写出去

        socket.shutdownOutput();

        //2.读取回写数据,读取服务端给的数据
        BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
        //获取字节输入流变成字符输入流，再变成缓冲字符输入流
        String line = br.readLine();
        System.out.println(line);
        //3.释放资源
        socket.close();
    }
}


//两个细节
//数据流向
//如何让他停止输入